package com.pucheng.bracelet.data.bean

import androidx.room.*
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

@Entity(tableName = "sleep")
@TypeConverters(SleepNodeConverters::class)
data class SleepBean(
    @PrimaryKey var date: String = "",
    @ColumnInfo var timestamp:Long = System.currentTimeMillis(),//睡眠时间
    @ColumnInfo var lightTime:Int = 0,//浅睡时间
    @ColumnInfo var restfulTime:Int = 0,//深睡时间
    @ColumnInfo var soberTime:Int = 0,//清醒时间
    @ColumnInfo var activeTime:Int = 0,//快速眼动时长
    @ColumnInfo var totalTime:Int = 0,//总睡眠时长
    @ColumnInfo var nodes:List<SleepNode> = arrayListOf()
)

class SleepNodeConverters {

    @TypeConverter
    fun stringToObject(value: String): List<SleepNode> {
        val listType = object : TypeToken<List<SleepNode>>() {

        }.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<SleepNode>): String {
        val gson = Gson()
        return gson.toJson(list)
    }
}

data class SleepNode(var min_offset:Int=0 ,var status:Int = 0)